package com.wontube.smr.cron;

import java.util.HashSet;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wontube.core.cron.IJobs;
import com.wontube.smr.bo.sites.imdb.ImdbObtainBO;

/**
 * @author tanggf(2012-7-30)
 *
 */
public class ObtainImdbJobs implements IJobs {
	private final static Logger logger = LoggerFactory.getLogger(ObtainImdbJobs.class);

	@Override
	public String name() {
		return "obtain-imdb";
	}

	@Override
	public IJobs execute(String[] args) {
		Set<String> set = new HashSet<String>();
		for (String arg : args) {
			set.add(arg);
		}
		
		if(set.contains("-trailler")){
			this.grabTraillers();
		}
		
		return this;
	}
	
	private void grabTraillers(){
		long start = System.currentTimeMillis();	
		int count = 0;
		try {
			count = ImdbObtainBO.obtainTrailer();
		} catch (Exception e) {
			logger.error("errors happen when grab imdb trailler", e);
		}
		long cost = System.currentTimeMillis() - start;
		cost /= 1000;
		logger.info("obtain {} imdb traillers, cost {} s", count, cost);		
	}
	
}
